#include <queue>

using namespace std;

class MyStack {
private:
    queue<int> data;
public:
    /** Initialize your data structure here. */
    MyStack() {}

    /** Push element x onto stack. */
    void push(int x) {
        queue<int> aux;
        aux.push(x);
        while (data.size() > 0) {
            int val = data.front();
            aux.push(val);
            data.pop();
        }
        data = aux;
    }

    /** Removes the element on top of the stack and returns that element. */
    int pop() {
        int ans = data.front();
        data.pop();
        return ans;
    }

    /** Get the top element. */
    int top() {
        return data.front();
    }

    /** Returns whether the stack is empty. */
    bool empty() {
        return data.size() == 0;
    }
};